home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / pcl / src-16f.lha / compiler / mips / nlx.lisp < prev    next >
Encoding:
Text File  |  1992-07-28  |  8.9 KB  |  286 lines

  1. ;;; -*- Package: MIPS -*-
  2. ;;;
  3. ;;; **********************************************************************
  4. ;;; This code was written as part of the CMU Common Lisp project at
  5. ;;; Carnegie Mellon University, and has been placed in the public domain.
  6. ;;; If you want to use this code or any part of CMU Common Lisp, please contact
  7. ;;; Scott Fahlman or slisp-group@cs.cmu.edu.
  8. ;;;
  9. (ext:file-comment
  10.   "$Header: nlx.lisp,v 1.17 92/05/21 23:23:29 wlott Locked $")
  11. ;;;
  12. ;;; **********************************************************************
  13. ;;;
  14. ;;; $Header: nlx.lisp,v 1.17 92/05/21 23:23:29 wlott Locked $
  15. ;;;
  16. ;;;    This file contains the definitions of VOPs used for non-local exit
  17. ;;; (throw, lexical exit, etc.)
  18. ;;;
  19. ;;; Written by Rob MacLachlan
  20. ;;;
  21. (in-package "MIPS")
  22.  
  23. ;;; MAKE-NLX-SP-TN  --  Interface
  24. ;;;
  25. ;;;    Make an environment-live stack TN for saving the SP for NLX entry.
  26. ;;;
  27. (def-vm-support-routine make-nlx-sp-tn (env)
  28.   (environment-live-tn
  29.    (make-representation-tn *fixnum-primitive-type* immediate-arg-scn)
  30.    env))
  31.  
  32.  
  33.  
  34. ;;; Save and restore dynamic environment.
  35. ;;;
  36. ;;;    These VOPs are used in the reentered function to restore the appropriate
  37. ;;; dynamic environment.  Currently we only save the Current-Catch and binding
  38. ;;; stack pointer.  We don't need to save/restore the current unwind-protect,
  39. ;;; since unwind-protects are implicitly processed during unwinding.  If there
  40. ;;; were any additional stacks, then this would be the place to restore the top
  41. ;;; pointers.
  42.  
  43.  
  44. ;;; Make-Dynamic-State-TNs  --  Interface
  45. ;;;
  46. ;;;    Return a list of TNs that can be used to snapshot the dynamic state for
  47. ;;; use with the Save/Restore-Dynamic-Environment VOPs.
  48. ;;;
  49. (def-vm-support-routine make-dynamic-state-tns ()
  50.   (make-n-tns 4 *any-primitive-type*))
  51.  
  52. (define-vop (save-dynamic-state)
  53.   (:results (catch :scs (descriptor-reg))
  54.         (nfp :scs (descriptor-reg))
  55.         (nsp :scs (descriptor-reg))
  56.         (eval :scs (descriptor-reg)))
  57.   (:vop-var vop)
  58.   (:generator 13
  59.     (load-symbol-value catch lisp::*current-catch-block*)
  60.     (let ((cur-nfp (current-nfp-tn vop)))
  61.       (when cur-nfp
  62.     (move nfp cur-nfp)))
  63.     (move nsp nsp-tn)
  64.     (load-symbol-value eval lisp::*eval-stack-top*)))
  65.  
  66. (define-vop (restore-dynamic-state)
  67.   (:args (catch :scs (descriptor-reg))
  68.      (nfp :scs (descriptor-reg))
  69.      (nsp :scs (descriptor-reg))
  70.      (eval :scs (descriptor-reg)))
  71.   (:vop-var vop)
  72.   (:generator 10
  73.     (store-symbol-value catch lisp::*current-catch-block*)
  74.     (store-symbol-value eval lisp::*eval-stack-top*)
  75.     (let ((cur-nfp (current-nfp-tn vop)))
  76.       (when cur-nfp
  77.     (move cur-nfp nfp)))
  78.     (move nsp-tn nsp)))
  79.  
  80. (define-vop (current-stack-pointer)
  81.   (:results (res :scs (any-reg descriptor-reg)))
  82.   (:generator 1
  83.     (move res csp-tn)))
  84.  
  85. (define-vop (current-binding-pointer)
  86.   (:results (res :scs (any-reg descriptor-reg)))
  87.   (:generator 1
  88.     (move res bsp-tn)))
  89.  
  90.  
  91.  
  92. ;;;; Unwind block hackery:
  93.  
  94. ;;; Compute the address of the catch block from its TN, then store into the
  95. ;;; block the current Fp, Env, Unwind-Protect, and the entry PC.
  96. ;;;
  97. (define-vop (make-unwind-block)
  98.   (:args (tn))
  99.   (:info entry-label)
  100.   (:results (block :scs (any-reg)))
  101.   (:temporary (:scs (descriptor-reg)) temp)
  102.   (:temporary (:scs (non-descriptor-reg)) ndescr)
  103.   (:generator 22
  104.     (inst addu block fp-tn (* (tn-offset tn) vm:word-bytes))
  105.     (load-symbol-value temp lisp::*current-unwind-protect-block*)
  106.     (storew temp block vm:unwind-block-current-uwp-slot)
  107.     (storew fp-tn block vm:unwind-block-current-cont-slot)
  108.     (storew code-tn block vm:unwind-block-current-code-slot)
  109.     (inst compute-lra-from-code temp code-tn entry-label ndescr)
  110.     (storew temp block vm:catch-block-entry-pc-slot)))
  111.  
  112.  
  113. ;;; Like Make-Unwind-Block, except that we also store in the specified tag, and
  114. ;;; link the block into the Current-Catch list.
  115. ;;;
  116. (define-vop (make-catch-block)
  117.   (:args (tn)
  118.      (tag :scs (descriptor-reg)))
  119.   (:info entry-label)
  120.   (:results (block :scs (any-reg)))
  121.   (:temporary (:scs (descriptor-reg)) temp)
  122.   (:temporary (:scs (descriptor-reg) :target block :to (:result 0)) result)
  123.   (:temporary (:scs (non-descriptor-reg)) ndescr)
  124.   (:generator 44
  125.     (inst addu result fp-tn (* (tn-offset tn) vm:word-bytes))
  126.     (load-symbol-value temp lisp::*current-unwind-protect-block*)
  127.     (storew temp result vm:catch-block-current-uwp-slot)
  128.     (storew fp-tn result vm:catch-block-current-cont-slot)
  129.     (storew code-tn result vm:catch-block-current-code-slot)
  130.     (inst compute-lra-from-code temp code-tn entry-label ndescr)
  131.     (storew temp result vm:catch-block-entry-pc-slot)
  132.  
  133.     (storew tag result vm:catch-block-tag-slot)
  134.     (load-symbol-value temp lisp::*current-catch-block*)
  135.     (storew temp result vm:catch-block-previous-catch-slot)
  136.     (store-symbol-value result lisp::*current-catch-block*)
  137.  
  138.     (move block result)))
  139.  
  140.  
  141. ;;; Just set the current unwind-protect to TN's address.  This instantiates an
  142. ;;; unwind block as an unwind-protect.
  143. ;;;
  144. (define-vop (set-unwind-protect)
  145.   (:args (tn))
  146.   (:temporary (:scs (descriptor-reg)) new-uwp)
  147.   (:generator 7
  148.     (inst addu new-uwp fp-tn (* (tn-offset tn) vm:word-bytes))
  149.     (store-symbol-value new-uwp lisp::*current-unwind-protect-block*)))
  150.  
  151.  
  152. (define-vop (unlink-catch-block)
  153.   (:temporary (:scs (any-reg)) block)
  154.   (:policy :fast-safe)
  155.   (:translate %catch-breakup)
  156.   (:generator 17
  157.     (load-symbol-value block lisp::*current-catch-block*)
  158.     (loadw block block vm:catch-block-previous-catch-slot)
  159.     (store-symbol-value block lisp::*current-catch-block*)))
  160.  
  161. (define-vop (unlink-unwind-protect)
  162.   (:temporary (:scs (any-reg)) block)
  163.   (:policy :fast-safe)
  164.   (:translate %unwind-protect-breakup)
  165.   (:generator 17
  166.     (load-symbol-value block lisp::*current-unwind-protect-block*)
  167.     (loadw block block vm:unwind-block-current-uwp-slot)
  168.     (store-symbol-value block lisp::*current-unwind-protect-block*)))
  169.  
  170.  
  171. ;;;; NLX entry VOPs:
  172.  
  173.  
  174. (define-vop (nlx-entry)
  175.   (:args (sp) ; Note: we can't list an sc-restriction, 'cause any load vops
  176.           ; would be inserted before the LRA.
  177.      (start)
  178.      (count))
  179.   (:results (values :more t))
  180.   (:temporary (:scs (descriptor-reg)) move-temp)
  181.   (:info label nvals)
  182.   (:save-p :force-to-stack)
  183.   (:vop-var vop)
  184.   (:generator 30
  185.     (emit-return-pc label)
  186.     (note-this-location vop :non-local-entry)
  187.     (cond ((zerop nvals))
  188.       ((= nvals 1)
  189.        (let ((no-values (gen-label)))
  190.          (inst beq count zero-tn no-values)
  191.          (move (tn-ref-tn values) null-tn)
  192.          (loadw (tn-ref-tn values) start)
  193.          (emit-label no-values)))
  194.       (t
  195.        (collect ((defaults))
  196.          (do ((i 0 (1+ i))
  197.           (tn-ref values (tn-ref-across tn-ref)))
  198.          ((null tn-ref))
  199.            (let ((default-lab (gen-label))
  200.              (tn (tn-ref-tn tn-ref)))
  201.          (defaults (cons default-lab tn))
  202.          
  203.          (inst beq count zero-tn default-lab)
  204.          (inst addu count count (fixnum -1))
  205.          (sc-case tn
  206.               ((descriptor-reg any-reg)
  207.                (loadw tn start i))
  208.               (control-stack
  209.                (loadw move-temp start i)
  210.                (store-stack-tn tn move-temp)))))
  211.          
  212.          (let ((defaulting-done (gen-label)))
  213.            
  214.            (emit-label defaulting-done)
  215.            
  216.            (assemble (*elsewhere*)
  217.          (dolist (def (defaults))
  218.            (emit-label (car def))
  219.            (let ((tn (cdr def)))
  220.              (sc-case tn
  221.                   ((descriptor-reg any-reg)
  222.                    (move tn null-tn))
  223.                   (control-stack
  224.                    (store-stack-tn tn null-tn)))))
  225.          (inst b defaulting-done)
  226.          (inst nop))))))
  227.     (load-stack-tn csp-tn sp)))
  228.  
  229.  
  230. (define-vop (nlx-entry-multiple)
  231.   (:args (top :target dst) (start :target src) (count :target num))
  232.   ;; Again, no SC restrictions for the args, 'cause the loading would
  233.   ;; happen before the entry label.
  234.   (:info label)
  235.   (:temporary (:scs (any-reg) :from (:argument 0)) dst)
  236.   (:temporary (:scs (any-reg) :from (:argument 1)) src)
  237.   (:temporary (:scs (any-reg) :from (:argument 2)) num)
  238.   (:temporary (:scs (descriptor-reg)) temp)
  239.   (:results (new-start) (new-count))
  240.   (:save-p :force-to-stack)
  241.   (:vop-var vop)
  242.   (:generator 30
  243.     (emit-return-pc label)
  244.     (note-this-location vop :non-local-entry)
  245.     (let ((loop (gen-label))
  246.       (done (gen-label)))
  247.  
  248.       ;; Copy args.
  249.       (load-stack-tn dst top)
  250.       (move src start)
  251.       (move num count)
  252.  
  253.       ;; Establish results.
  254.       (sc-case new-start
  255.     (any-reg (move new-start dst))
  256.     (control-stack (store-stack-tn new-start dst)))
  257.       (inst beq num zero-tn done)
  258.       (sc-case new-count
  259.     (any-reg (inst move new-count num))
  260.     (control-stack (store-stack-tn new-count num)))
  261.  
  262.       ;; Copy stuff on stack.
  263.       (emit-label loop)
  264.       (loadw temp src)
  265.       (inst addu src src vm:word-bytes)
  266.       (storew temp dst)
  267.       (inst addu num num (fixnum -1))
  268.       (inst bne num zero-tn loop)
  269.       (inst addu dst dst vm:word-bytes)
  270.  
  271.       (emit-label done)
  272.       (inst move csp-tn dst))))
  273.  
  274.  
  275. ;;; This VOP is just to force the TNs used in the cleanup onto the stack.
  276. ;;;
  277. (define-vop (uwp-entry)
  278.   (:info label)
  279.   (:save-p :force-to-stack)
  280.   (:results (block) (start) (count))
  281.   (:ignore block start count)
  282.   (:vop-var vop)
  283.   (:generator 0
  284.     (emit-return-pc label)
  285.     (note-this-location vop :non-local-entry)))
  286.